package com.naiterui.ehp.bs.emr.utils.his.param.resp;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yiren
 * @since 2022/1/26
 */
@Data
@Builder
public class AnalyzeResp {
	private String inquirerName;
	/**
	 * 性别
	 */
	private String gender;

	/**
	 * 年龄
	 */
	private String age;

	/**
	 * 申请科室
	 */
	private String applyDepartment;

	/**
	 * 申请医生
	 */
	private String applyDoctor;

	/**
	 * 申请时间
	 */
	private String applyTime;

	/**
	 * 样本类型
	 */
	private String sampleType;

	/**
	 * 临床诊断
	 */
	private String diagnosis;

	/**
	 * 化验名称
	 */
	private String analyzeName;

	/**
	 * 化验结果
	 */
	private List<AnalyzeResult> items;

	public static AnalyzeResp of (JSONObject json) {
		List<AnalyzeResult> results = new ArrayList<>();
		JSONArray resultArray = json.getJSONArray("xxmx");
		resultArray.jsonIter().forEach(js -> results.add(AnalyzeResult.of(js)));
		String applyDepartment = json.getStr("apply_dept");
		return AnalyzeResp.builder()
				.inquirerName(json.getStr("name"))
				.analyzeName(json.getStr("xmmc"))
				.gender(json.getStr("gender"))
				.age(json.getStr("age"))
				.applyDepartment(applyDepartment == null ? "" : applyDepartment.trim())
				.applyDoctor(json.getStr("apply_doctor"))
				.applyTime(json.getStr("apply_time"))
				.sampleType(json.getStr("sample_type"))
				.diagnosis(json.getStr("diagnosi"))
				.items(results)
				.build();
	}
}
